import { DataService } from './../../../../../services/data.service';
import { Component, OnInit } from '@angular/core';
import { MiCheckService } from './mi-check.service';
import * as _ from "lodash";
import { Data } from '@angular/router/src/config';

@Component({
  selector: 'app-mi-check',
  templateUrl: './mi-check.component.html',
  styleUrls: ['./mi-check.component.scss'],
  providers: [MiCheckService]
})
export class MiCheckComponent implements OnInit {

  //产品内码
  public nRid;
  // 产品信息
  public singleInfo: any = {
    // nRid: this.nRid,
    // sOperpoint:'',//操作点
    // sTitle:'',//摘要
    // sContent: '',//内容
    // sTmpTitle: '',//临时摘要
    // sTmpContent: '',//临时内容
    // sStatus: ''//状态
  }

  constructor(
    public checkService: MiCheckService,
    public dataService: DataService
  ) { }

  ngOnInit() {
    // this.GetSingleInfo();
  }

  // 查询数据信息
  // GetSingleInfo(){
  //   let that = this;
  //   this.checkService.getInfo(this.nRid).subscribe(data => {
  //     if (data) {
  //       that.singleInfo = data;
  //       console.info(this.singleInfo)
  //     }
  //   });
  // }

  // 审核通过
  checkPass() {
    let that = this;
    let checkProduct = this.singleInfo;
    window["swal"]({
      title: "注意",
      text: "是否确定审核通过",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          let putBody = {
            nRid: that.singleInfo.nRid,
            sOperpoint: that.singleInfo.sOperpoint,//操作点
            sTitle: that.singleInfo.sTitle,//摘要
            sContent: that.singleInfo.sContent,//内容
            sTmpTitle: that.singleInfo.sTmpTitle,//临时摘要
            sTmpContent: that.singleInfo.sTmpContent,//临时内容
            sStatus: that.singleInfo.sStatus,//状态
          }
          that.checkService.checkPass(putBody).subscribe(data => {
            if (data) {
              window['swal']("成功", "已审核!", "success");
              that.dataService.rcmiCheckEmitter.emit('check');
            }
          })
        }
      })
  }

  // 审核不通过
  checkNotPass() {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定审核不通过",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          let putBody = {
            nRid: that.singleInfo.nRid,
            sOperpoint: that.singleInfo.sOperpoint,//操作点
            sTitle: that.singleInfo.sTitle,//摘要
            sContent: that.singleInfo.sContent,//内容
            sTmpTitle: that.singleInfo.sTmpTitle,//临时摘要
            sTmpContent: that.singleInfo.sTmpContent,//临时内容
            sStatus: that.singleInfo.sStatus,//状态
          }
          that.checkService.checkNotPass(putBody).subscribe(data => {
            if (data) {
              window['swal']("成功", "已审核!", "success");
              that.dataService.rcmiCheckEmitter.emit('check');
            }
          })
        }
      })
  }

}
